Skip to content

Fix clash with Windows min/max macros (completes #52) - #57

Merged
martinus merged 2 commits into
mainfrom
pr/52-windows-minmax
Jul 27, 2026
Merged

Fix clash with Windows min/max macros (completes #52)#57
martinus merged 2 commits into
mainfrom
pr/52-windows-minmax

Conversation

@martinus

Copy link
Copy Markdown
Owner

Completes #52 by @T-640. Their original commit is preserved as the first commit here, since [maintainer pushes to their fork are not possible from this environment]; merging this will close #52 as merged.

The problem

Including <Windows.h> without NOMINMAX defines min/max as function-like macros, breaking svector.h.

What the original PR did

Parenthesized 4 sites (lines 137, 167, 320, 849) so min/max is not followed by ( and the macro is not invoked. Correct approach, but incomplete.

What this adds

1. Three missed call sites. erase() and the move helper still used unparenthesized std::min, so anyone calling erase()/insert() still could not compile:

  • svector.h:408std::min(const_cast<T*>(to), container_end)
  • svector.h:469std::min(num_moves, std::distance(...))
  • svector.h:472std::min(source_end, target_begin)

Measured by compiling a TU that defines the Windows min/max macros before including the header:

errors
main 9
#52 as submitted 3
this branch 0

2. Indentation. The four original lines used tabs; .clang-format sets UseTab: Never, so the lint job rejected them. Converted to spaces — ./scripts/lint/lint-all.py now passes.

std::max<size_t>(1, starting_capacity) at line 310 is deliberately left alone: the explicit template argument makes max be followed by <, so the function-like macro never fires.

Verification

meson test: Ok: 2, Fail: 0 (56986 assertions). Lint clean.

Depends on #56 for CI to actually run green.

🤖 Generated with Claude Code

T-640 and others added 2 commits July 27, 2026 17:42
Fixes clash with Windows "min" and "max" macros
Follow-up to the original fix:

* erase() and the move helper still called std::min unparenthesized at
  lines 408, 469 and 472, so <Windows.h> without NOMINMAX still failed
  to compile for anyone using erase()/insert(). Simulating the Windows
  min/max macros, main produced 9 errors and the original patch left 3;
  now it compiles clean.
* The four touched lines used tabs, but .clang-format sets
  UseTab: Never, so the lint job rejected them. Converted to spaces.

std::max<size_t>(1, starting_capacity) at line 310 deliberately stays
as is: an explicit template argument makes 'max' be followed by '<'
rather than '(', so the function-like macro is never invoked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@martinus
martinus force-pushed the pr/52-windows-minmax branch from 6c7c74e to 47d2f42 Compare July 27, 2026 15:42
@martinus
martinus merged commit 3d87e9c into main Jul 27, 2026
8 checks passed
@martinus
martinus deleted the pr/52-windows-minmax branch July 27, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants